package com.xsz.pda.data.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.xsz.pda.data.bean.CheckRecord
import com.xsz.pda.data.bean.GroupType
import com.xsz.pda.data.bean.Ticket
import com.xsz.pda.data.bean.TicketItem

@Database(
    entities = [
        Ticket::class,
        CheckRecord::class,
        TicketItem::class,
        GroupType::class
   ],
    version = 1,
    exportSchema = false
)
abstract class LocalDB : RoomDatabase() {


    abstract fun ticketDao(): TicketDao
    abstract fun checkRecordDao(): CheckRecordDao
    abstract fun ticketItemDao(): TicketItemDao
    abstract fun typeGroupDao(): GroupTypeDao

    companion object {
        private var instance: LocalDB? = null

        @Synchronized
        fun get(context: Context): LocalDB {
            if (instance == null) {
                instance = Room.databaseBuilder(
                    context.applicationContext,
                    LocalDB::class.java,
                    "localDatabase"
                ).build()
            }
            return instance!!
        }
    }
}


